﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using ProjectRoughWork.Engine.SoundManager;

namespace ProjectRoughWork
{
    class PauseScreen : GameScreen
    {
        /// <summary>
        /// Default Constructor. Initializes necessary components to display the pause screen
        /// </summary>

        public PauseScreen()
        {
            //Initialize width and height

            width = Game1.GetGraphicsDevice().Viewport.Width/2;
            height = Game1.GetGraphicsDevice().Viewport.Height/2;

            //Initialize components to draw pause screen background

            origin = new Vector2(width / 4, height / 4);
            position = new Vector2(width / 2, height / 2);
            drawBox = new Rectangle(0, 0, width, height);

            //Retrieve things necessary to draw

            spriteBatch = Game1.GetSpriteBatch();
            spriteFont = Game1.GetSpriteFont();
            pauseBg = Game1.GetContentManager().Load<Texture2D>("MenuBg");

            popup = true;

            // Pause our background music
            SoundManager.GetInstance().pauseBackgroundMusic();
        }

        

        public override void HandleInput(KeyboardState inputKey)
        {
            if ((inputKey.IsKeyDown(Keys.Escape)) &&
                (lastKeyInput.IsKeyUp(Keys.Escape))
                )
            {
                //Close the pause screen if Escape is pressed
                SoundManager.GetInstance().resumeBackgroundMusic();
                ScreenManager.GetInstance().popScreen();
            }

            lastKeyInput = inputKey;

            base.HandleInput(inputKey);
        }

        public override void HandleInput(GamePadState inputButton)
        {

            if ((inputButton.IsButtonDown(Buttons.Start)) &&
                (lastButtonInput.IsButtonUp(Buttons.Start))
                )
            {
                //Close the pause screen if the start button is pressed 
                ScreenManager.GetInstance().popScreen();
            }

            lastButtonInput = inputButton;

            base.HandleInput(inputButton);
        }

        public override void Draw()
        {
            base.Draw();

            spriteBatch.Begin();

            spriteBatch.Draw(pauseBg, position, drawBox, Color.White, 0, origin, 1f, SpriteEffects.None, 0);

            spriteBatch.End();
        }
     
        //Data Members

        int width;                      //The width of the screen
        int height;                     //The height of the screen
        Vector2 origin;                 //Text Origin
        Vector2 position;           

        Texture2D pauseBg;              //Background Image of the pause screen
        Rectangle drawBox;              //Rectangle to draw texture
        SpriteBatch spriteBatch;        
        SpriteFont spriteFont;
    }
}
